package cn.cmkj.auction.ui;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import cn.cmkj.auction.R;
import cn.cmkj.auction.app.BaseActivity;
import cn.cmkj.auction.widget.X5WebView;

@ContentView(R.layout.activity_webview)
public class BrowserActivity extends BaseActivity implements View.OnClickListener {

	@ViewInject(R.id.title_back)
	private ImageButton titleBack;
	@ViewInject(R.id.title_text)
	private TextView titleText;
	@ViewInject(R.id.webview)
	private X5WebView mWebView;

	public static final String TITLE = "title";
	public static final String URL = "url";
	private String title;
	private String url;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		x.view().inject(this);
		Intent intent = getIntent();
		if(intent == null) {
			finish();
			return;
		}
		title = intent.getStringExtra(TITLE);
		url = intent.getStringExtra(URL);
		if(title != null && !"".equals(title)) {
			titleText.setText(title);
		}else {
			titleText.setText("详情");
		}
		mWebView.loadUrl(url);
		WebSettings webSettings = mWebView.getSettings();
		webSettings.setJavaScriptEnabled(true);
		mWebView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		titleBack.setOnClickListener(this);
	}


	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.title_back:
				finish();
				break;
		}
	}
}
